package com.zds.scm.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zds.scm.common.CommonServlet;
import com.zds.scm.domain.TeacherInfo;
import static com.zds.scm.common.util.StringUtils.isNull;
public class TeacherInfoServlet extends CommonServlet {

	private static final long serialVersionUID = 4475040933223556033L;
	private TeacherInfo teacherInfo=new TeacherInfo();
	public void setTeacherInfo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.debug("1.获取表单参数");
		logger.debug("2.按照domain对象的要求做类型转换");
		logger.debug("3.填充domain对象");
		logger.debug("4.验证参数是否符合要求");
		teacherInfo.setDeptCode(request.getParameter("deptCode"));
		teacherInfo.setTeacherCode(request.getParameter("teacherCode"));
		teacherInfo.setTeacherName(request.getParameter("teacherName"));
		teacherInfo.setTeacherMobile(request.getParameter("teacherMobile"));
		if (isNull(teacherInfo.getDeptCode())
				|| isNull(teacherInfo.getTeacherCode())
				|| isNull(teacherInfo.getTeacherName())) {
			logger.debug("4.验证参数是否符合要求失败");
			request.setAttribute("message", "教师系别/教师工号/教师名称都不能为空");
			throw new ServletException();
		}
	}
	public void insert(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.debug("执行insert方法");
		try {
			setTeacherInfo(request, response);
			//TODO 增加教师信息,并根据增加成功与否,执行相应的跳转
		} catch (Exception e) {
		}
		
		
		//重定向到上下文路径中的登陆页面,转发时地址栏的信息会改变,request.setAttribute("", "");中设置的值，不能在重定向的页面访问
		//response.sendRedirect(request.getContextPath()+"/");  
		//转发到当前上下文路径的登陆页面,转发时地址栏的信息不变,request.setAttribute("", "");中设置的值，在可以在转发的页面中访问
		request.getRequestDispatcher("/").forward(request, response);
	}
	public void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.debug("执行delete方法");
		//TODO 删除指定教师,根据成功与否,执行相应的跳转
	}
	public void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.debug("执行update方法");
		//TODO 更新指定教师,根据成功与否,执行相应的跳转
	}
	public void findById(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.debug("执行update方法");
		//TODO 根据传入的code查找教师详细信息,,根据成功与否,执行相应的跳转
	}
	public void findAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.debug("执行update方法");
		//TODO 分页查询所有教师信息,根据成功与否,执行相应的跳转
	}
}
